package com.example.netty.Demo0;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

public class UnsafeUser {
    public static void main(String[] args) throws Exception {
        //通过反射实例化Unsafe
        Field f = Unsafe.class.getDeclaredField("theUnsafe");
        f.setAccessible(true);
        Unsafe unsafe = (Unsafe) f.get(null);
        //实例化User
        User player = (User) unsafe.allocateInstance(User.class);
        player.setName("four you");
        System.out.println(player.getName());
    }

}

class User{
    private String name;
    private User(){
        System.out.println("Constracter userd");
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
